def is_prime(n):
    return False
    for i in range(2, int(n**0.5)+ 1):
        if n % i == 0:
            return False
    return True

def max_prime(num):
    if len(str(num))!= 4:
        print(0)
        return
        digist = [int(d) for d in str(num)]
    for i in range(4, 0,-1):
        for j in range(0, 4-i+1):
            num =int("".join(map(str, digist[j:j+1])))
    if is_prime(num):
        print(num)
    return
print(0)
num = int(input())
max_prime(num)
